using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NReadability;
using System.Net;
using System.Text;
using EpubLibrary;
using HtmlAgilityPack;
using System.IO;

public partial class ViewPage : System.Web.UI.Page
{
    protected string content = "";
    protected string url = "";
    protected string host = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        url = Request.QueryString["url"].ToString();
        string type = Request.QueryString["type"] == null ? "" : Request.QueryString["type"];
        bool success;        
        url = Uri.UnescapeDataString(url);
        Uri uri = new Uri(url);
        host = uri.Host;

        content = url;
        WebClient web = new WebClient();
        web.Encoding = Encoding.UTF8;

        //Added by manhlq, 13/06/2009
        web.Headers.Add("user-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10)");

        content = web.DownloadString(url);

        if (type == "1")
        {
            content = EpubFactory.extractMainContentOfImagesPage(url, Convert.ToInt32(320));
        }
        else
        {
            //NReadabilityTranscoder transcoder = new NReadabilityTranscoder();

            //content = transcoder.Transcode(content, out success);
            Readability ability = new Readability(false, true, true, EpubLibrary.ReadingStyle.Newspaper, EpubLibrary.ReadingMargin.Medium, EpubLibrary.ReadingSize.Medium);
            HtmlDocument document =  EpubLibrary.Content.LoadContent(url);
            ability.document = document;
            HtmlNode node = ability.getContent(true);
            content = node.InnerHtml;
        }
    }
}
